#ifndef ARDUINOPLATFORM_H_
#define ARDUINOPLATFORM_H_

typedef unsigned char byte;



enum CurrentMode
{
	ModeNone = -1,
	ModeWelcome = 0,
	ModeOperatorId = 1,
	ModeBarcode = 2,
	ModeDefect = 3,
	ModeSummary = 4,
	ModeSubmit = 5
};

#include "D:\arduino-1.0.1\hardware\arduino\variants\standard\pins_arduino.h"
#include "D:\arduino-1.0.1\hardware\arduino\cores\arduino\Arduino.h"

#include <EEPROM.h>
#include "libs/EEPROMAnything.h"
#include <avr/pgmspace.h>
#include <PinChangeInt.h>
#include "libs/BarcodeItem.h"
#include <LiquidCrystal.h>
#include <analogKey.h>
#include <util/crc16.h>
#include "libs/LppgmProtocol.h"
#include "libs/Melody.h"
//#include <string.h>
//#include <ModbusMaster.h>

PROGMEM const int8_t ee_devices_id = 0; //int8_t
PROGMEM const int8_t ee_ready = 1;

int DeviceID = 0x01;
int8_t WaitForSend = 0;
//const int pinA0 = 14; //defect id bit 0.
//const int pinA1 = 15; //defect id bit 1.
//const int pinA2 = 16; //defect id bit 2.
//const int pinA3 = 17; //defect id key press.
//const int pinA4 = 18; //Numpad keys.

//const int defaultVal = -1;
const char STR_INIT[] = "INITIALIZING...";

void WelcomeFunc();
void OperatorFunc();
void BarcodeFunc();
void DefectFunc();
void SummaryFunc();
void SubmitFunc();
void DefaultFunc();

//void SendSerial(char[]);
//char* ReadFromSerial();
void ProcessSerialString();
void DisplayDefect();
void DisplayOperator(char[]);

//byte hex2num(byte x);
//void sendMSG(byte type, byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4);
//void sendACK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4);
//void sendNAK(byte address1,byte address2,byte data_type,byte code1,byte code2,byte Sign,byte data1,byte data2,byte data3,byte data4);
//
static void clearChar(char *c)
{
	for(int x = 0; x < sizeof(c); x++)
	c[x] = NULL;
}

// variables created by the build process when compiling the sketch
extern int __bss_end;
extern void *__brkval;
// function to return the amount of free RAM
int memoryFree()
{
	int freeValue;
	if((int)__brkval == 0)
	freeValue = ((int)&freeValue) - ((int)&__bss_end);
	else
	freeValue = ((int)&freeValue) - ((int)__brkval);
	return freeValue;
}

#endif